{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "038a4d91",
   "metadata": {},
   "source": [
    "---\n",
    "* 2023-10-25\n",
    "* 课程：python语言\n",
    "* week06（上课周）\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a4ae70b",
   "metadata": {},
   "source": [
    "# 1、项目一详解"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "821b8b6c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前时钟的分钟是偶数\n"
     ]
    }
   ],
   "source": [
    "# 项目一：判断当前时钟的分钟是否为奇数\n",
    "\n",
    "from datetime import datetime\n",
    "\n",
    "# odds是一个变量，存放奇数数组（列表）1-59 特指分钟的奇数数值\n",
    "odds = [  1, 3,  5,  7,  9, 11,13,15,17,19,\n",
    "             21,23,25,27,29,31,33,35,37,39,\n",
    "             41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "#使用了datetime模块中的datetime方法，用today（）获取当前的时钟（年月日时分秒），选择出分钟minute作为我们的right_this_minute\n",
    "right_this_minute = datetime.today().minute\n",
    "# 判断当前时钟分钟是否在odds这个变量数组里面\n",
    "if right_this_minute in odds:\n",
    "# 1.条件一：在odds里面，为奇数分钟时间\n",
    "    print(\"当前时钟的分钟为奇数\")\n",
    "else:\n",
    "# 2.条件二：不在odds，为偶数分钟时间\n",
    "    print(\"当前时钟的分钟是偶数\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "76d1f945",
   "metadata": {},
   "source": [
    "# 2、项目二详解"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5174717",
   "metadata": {},
   "source": [
    "> 1. 使用for循环迭代项目一，让执行次数为五次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d3d19d59",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.14840323603368055"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# random 随机数的练习，random和randint两个方法\n",
    "import random\n",
    "\n",
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4eb88716",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "27\n",
      "5\n",
      "36\n",
      "68\n",
      "51\n",
      "53\n"
     ]
    }
   ],
   "source": [
    "for i in range(7):\n",
    "    print(int(random.random()*100))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6f5f6a07",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.randint(0,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "1a8cb679",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前时钟为偶数秒钟,为18秒,时间即将静止1秒\n",
      "当前时钟为偶数秒钟,为19秒,时间即将静止4秒\n",
      "当前时钟为偶数秒钟,为23秒,时间即将静止1秒\n",
      "当前时钟为偶数秒钟,为24秒,时间即将静止4秒\n",
      "当前时钟为偶数秒钟,为28秒,时间即将静止5秒\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds = []\n",
    "\n",
    "# for+range可以决定执行循环的次数，如以下for循环执行了5次\n",
    "for i in range(5):\n",
    "    #等待时间是一个1-5之间的整数秒钟\n",
    "    wait_time = random.randint(1,5)\n",
    "    \n",
    "    #\n",
    "    right_this_second = datetime.today().second\n",
    "    #\n",
    "    if right_this_second in odds:\n",
    "        print(\"当前时钟为奇数秒钟,为%s秒,时间即将静止%s秒\"%(right_this_second,wait_time))\n",
    "    else:\n",
    "        print(\"当前时钟为偶数秒钟,为%s秒,时间即将静止%s秒\"%(right_this_second,wait_time))\n",
    "    #sleep：程序停止时间（秒）\n",
    "    time.sleep(wait_time)    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a956bc1",
   "metadata": {},
   "source": [
    "# 3、项目三：啤酒颂"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2c839b81",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "3\n",
      "6\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for i in range(0,10,3):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7fff8f02",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 bottles 在啤酒墙上~\n",
      "99 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "98 bottles 在啤酒墙上~\n",
      "98 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "97 bottles 在啤酒墙上~\n",
      "97 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "96 bottles 在啤酒墙上~\n",
      "96 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "95 bottles 在啤酒墙上~\n",
      "95 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "94 bottles 在啤酒墙上~\n",
      "94 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "93 bottles 在啤酒墙上~\n",
      "93 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "92 bottles 在啤酒墙上~\n",
      "92 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "91 bottles 在啤酒墙上~\n",
      "91 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "90 bottles 在啤酒墙上~\n",
      "90 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "89 bottles 在啤酒墙上~\n",
      "89 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "88 bottles 在啤酒墙上~\n",
      "88 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "87 bottles 在啤酒墙上~\n",
      "87 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "86 bottles 在啤酒墙上~\n",
      "86 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "85 bottles 在啤酒墙上~\n",
      "85 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "84 bottles 在啤酒墙上~\n",
      "84 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "83 bottles 在啤酒墙上~\n",
      "83 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "82 bottles 在啤酒墙上~\n",
      "82 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "81 bottles 在啤酒墙上~\n",
      "81 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "80 bottles 在啤酒墙上~\n",
      "80 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "79 bottles 在啤酒墙上~\n",
      "79 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "78 bottles 在啤酒墙上~\n",
      "78 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "77 bottles 在啤酒墙上~\n",
      "77 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "76 bottles 在啤酒墙上~\n",
      "76 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "75 bottles 在啤酒墙上~\n",
      "75 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "74 bottles 在啤酒墙上~\n",
      "74 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "73 bottles 在啤酒墙上~\n",
      "73 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "72 bottles 在啤酒墙上~\n",
      "72 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "71 bottles 在啤酒墙上~\n",
      "71 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "70 bottles 在啤酒墙上~\n",
      "70 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "69 bottles 在啤酒墙上~\n",
      "69 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "68 bottles 在啤酒墙上~\n",
      "68 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "67 bottles 在啤酒墙上~\n",
      "67 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "66 bottles 在啤酒墙上~\n",
      "66 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "65 bottles 在啤酒墙上~\n",
      "65 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "64 bottles 在啤酒墙上~\n",
      "64 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "63 bottles 在啤酒墙上~\n",
      "63 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "62 bottles 在啤酒墙上~\n",
      "62 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "61 bottles 在啤酒墙上~\n",
      "61 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "60 bottles 在啤酒墙上~\n",
      "60 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "59 bottles 在啤酒墙上~\n",
      "59 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "58 bottles 在啤酒墙上~\n",
      "58 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "57 bottles 在啤酒墙上~\n",
      "57 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "56 bottles 在啤酒墙上~\n",
      "56 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "55 bottles 在啤酒墙上~\n",
      "55 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "54 bottles 在啤酒墙上~\n",
      "54 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "53 bottles 在啤酒墙上~\n",
      "53 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "52 bottles 在啤酒墙上~\n",
      "52 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "51 bottles 在啤酒墙上~\n",
      "51 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "50 bottles 在啤酒墙上~\n",
      "50 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "49 bottles 在啤酒墙上~\n",
      "49 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "48 bottles 在啤酒墙上~\n",
      "48 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "47 bottles 在啤酒墙上~\n",
      "47 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "46 bottles 在啤酒墙上~\n",
      "46 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "45 bottles 在啤酒墙上~\n",
      "45 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "44 bottles 在啤酒墙上~\n",
      "44 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "43 bottles 在啤酒墙上~\n",
      "43 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "42 bottles 在啤酒墙上~\n",
      "42 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "41 bottles 在啤酒墙上~\n",
      "41 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "40 bottles 在啤酒墙上~\n",
      "40 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "39 bottles 在啤酒墙上~\n",
      "39 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "38 bottles 在啤酒墙上~\n",
      "38 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "37 bottles 在啤酒墙上~\n",
      "37 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "36 bottles 在啤酒墙上~\n",
      "36 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "35 bottles 在啤酒墙上~\n",
      "35 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "34 bottles 在啤酒墙上~\n",
      "34 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "33 bottles 在啤酒墙上~\n",
      "33 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "32 bottles 在啤酒墙上~\n",
      "32 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "31 bottles 在啤酒墙上~\n",
      "31 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "30 bottles 在啤酒墙上~\n",
      "30 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "29 bottles 在啤酒墙上~\n",
      "29 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "28 bottles 在啤酒墙上~\n",
      "28 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "27 bottles 在啤酒墙上~\n",
      "27 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "26 bottles 在啤酒墙上~\n",
      "26 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "25 bottles 在啤酒墙上~\n",
      "25 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "24 bottles 在啤酒墙上~\n",
      "24 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "23 bottles 在啤酒墙上~\n",
      "23 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "22 bottles 在啤酒墙上~\n",
      "22 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "21 bottles 在啤酒墙上~\n",
      "21 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "20 bottles 在啤酒墙上~\n",
      "20 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "19 bottles 在啤酒墙上~\n",
      "19 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "18 bottles 在啤酒墙上~\n",
      "18 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "17 bottles 在啤酒墙上~\n",
      "17 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "16 bottles 在啤酒墙上~\n",
      "16 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "15 bottles 在啤酒墙上~\n",
      "15 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "14 bottles 在啤酒墙上~\n",
      "14 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "13 bottles 在啤酒墙上~\n",
      "13 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "12 bottles 在啤酒墙上~\n",
      "12 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "11 bottles 在啤酒墙上~\n",
      "11 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "10 bottles 在啤酒墙上~\n",
      "10 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "9 bottles 在啤酒墙上~\n",
      "9 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "8 bottles 在啤酒墙上~\n",
      "8 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "7 bottles 在啤酒墙上~\n",
      "7 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "6 bottles 在啤酒墙上~\n",
      "6 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "5 bottles 在啤酒墙上~\n",
      "5 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "4 bottles 在啤酒墙上~\n",
      "4 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "3 bottles 在啤酒墙上~\n",
      "3 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "\n",
      "2 bottles 在啤酒墙上~\n",
      "2 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "1 bottle 在啤酒墙上~\n",
      "\n",
      "1 bottles 在啤酒墙上~\n",
      "1 bottles 啤酒~\n",
      "一次1瓶酒~\n",
      "取走一次\n",
      "没了没了，没有酒啦~\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 啤酒墙，每一次拿走一瓶啤酒，直到全部拿完，就没有了\n",
    "\n",
    "word = \"bottles\"\n",
    "# range决定起始的啤酒数量，当前为99；range决定每一次拿走多少瓶走，当前为1\n",
    "for beer_num in range(99, 0, -1):\n",
    "    print(beer_num,\"bottles\",\"在啤酒墙上~\")\n",
    "    print(beer_num,\"bottles\",\"啤酒~\")\n",
    "    print(\"一次1瓶酒~\")\n",
    "    print(\"取走一次\")\n",
    "    # 判断啤酒数量是否为1\n",
    "    if beer_num == 1:\n",
    "        # 如果beer_number为1 new_num 已经为0了，则没有了\n",
    "        print(\"没了没了，没有酒啦~\")\n",
    "    else:\n",
    "        # 当beer_number为2时候\n",
    "        new_num = beer_num - 1\n",
    "        # 当beer_number为1时候\n",
    "        if new_num == 1:\n",
    "            # 把bottles改为单数bottle\n",
    "            word = \"bottle\"\n",
    "            print(new_num, word, \"在啤酒墙上~\")\n",
    "    print()\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e852b266",
   "metadata": {},
   "source": [
    "# while循环\n",
    "\n",
    "* while True\n",
    "> 1. while一般和True一起使用，表示无限循环\n",
    "> 2. while True 一般在程序过程内部可以执行一个条件，当条件成立时结束此循环\n",
    "> 3. 结束循环：break"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ff66444",
   "metadata": {},
   "source": [
    "> 1. while循环认知\n",
    "> 2. while True\n",
    "> 3. while 与 for循环区别\n",
    "> 4. while 循环实践（猜数字）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "a5e0a9b3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是风儿我是沙,缠缠绵绵到天涯... 1\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 2\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 3\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 4\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 5\n"
     ]
    }
   ],
   "source": [
    "count = 0 # 计数器\n",
    "while True:\n",
    "    count +=1 # count = count + 1\n",
    "    print(\"你是风儿我是沙,缠缠绵绵到天涯...\",count)\n",
    "    if count == 5:\n",
    "        break # 终止循环"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "144b4b4c",
   "metadata": {},
   "source": [
    "## 2. 猜数字小游戏\n",
    "\n",
    "> 1. 给一个隐藏的小卡片（背后有一个数字1-100）\n",
    "> 2. 邀请一位小伙伴来猜数字（指定五次机会）\n",
    "> 3. 一共两种可能\n",
    ">> 1. 猜对了，break，game over successed！\n",
    ">> 1. 猜错了，（多一次判断，尝试次数是否够五次）\n",
    ">>> 1. 如果比隐藏卡片的数值大，我们将给一些提示，例如往小一点猜\n",
    ">>> 1. 如果比隐藏卡片的数值小，我们将给一些提示，例如往大一点猜"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0a2ee372",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 猜数字\n",
    "import getpass\n",
    "\n",
    "# 1. 拿数字给别人猜\n",
    "hide_card  = getpass.getpass(\"出题人请输入你心中的数字\")\n",
    "\n",
    "while True:\n",
    "    game_users = input(\"请输入你心中的数字\")\n",
    "     # 情景一：猜对了\n",
    "    if hide_card == guess_digit:\n",
    "        print(\"你真棒！猜对了\")\n",
    "        break\n",
    "    # 情景二：猜错了\n",
    "        else:\n",
    "        if hide_card > guess_digit:\n",
    "            print(\"往大了猜！\")\n",
    "        elif  hide_card < guess_digit:\n",
    "            print(\"数值比你的数小！\")\n",
    "\n",
    "            \n",
    "# 2. 设置猜游戏的次数\n",
    "count = 5\n",
    "\n",
    "while True:\n",
    "    count -=1\n",
    "    # 2. 猜数字的人来猜\n",
    "    print(\"你有%s次机会来玩这个游戏\"%(count))\n",
    "    if count == 0:\n",
    "        print(\"游戏失败！\")\n",
    "        break\n",
    "    else:"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
